// 格式化时间工具
// 年月日
function formatTime(time) {
  time = new Date(time);
  const year = time.getFullYear();
  let month = time.getMonth() + 1;
  let day = time.getDate();
  month = month >= 10 ? month : "0" + month;
  day = day >= 10 ? day : "0" + day;
  return `${year}.${month}.${day}`;
}

// 年月日小时分钟
function formatTimeToHHMM(time) {
  time = new Date(time);
  const year = time.getFullYear();
  let month = time.getMonth() + 1;
  let day = time.getDate();
  let hour = time.getHours();
  let minute = time.getMinutes();
  month = month >= 10 ? month : "0" + month;
  hour = hour >= 10 ? hour : "0" + hour;
  minute = minute >= 10 ? minute : "0" + minute;
  return `${year}.${month}.${day} ${hour}:${minute}`;
}

// 年月日小时分钟秒
function formatTimeToHHMMSS(time) {
  time = new Date(time);
  const year = time.getFullYear();
  let month = time.getMonth() + 1;
  let day = time.getDate();
  let hour = time.getHours();
  let minute = time.getMinutes();
  let second = time.getSeconds();
  month = month >= 10 ? month : "0" + month;
  hour = hour >= 10 ? hour : "0" + hour;
  minute = minute >= 10 ? minute : "0" + minute;
  second = second >= 10 ? second : "0" + second;
  return `${year}.${month}.${day} ${hour}:${minute}:${second}`;
}

// 订阅消息格式化时间
function formatTimeForSubscribe(){
      let dateNow = new Date(),
          year = dateNow.getFullYear(),
          month = dateNow.getMonth() + 1,
          day = dateNow.getDate(),
          hour = dateNow.getHours(),
          minute = dateNow.getMinutes();
          month = month >= 10 ? month : "0" + month;
          day = day >= 10 ? day : "0" + day;
          hour = hour >= 10 ? hour : "0" + hour;
          minute = minute >= 10 ? minute : "0" + minute;
      return `${year}-${month}-${day} ${hour}:${minute}`;
}

export default { formatTime, formatTimeToHHMM, formatTimeToHHMMSS, formatTimeForSubscribe };
